var cloneGraph = function (node) {
  if (!node) return node;
  let map = {};
  return dfs(node);

  function dfs(node) {
    let clone = new Node(node.val);
    map[clone.val] = clone;
    for (let neighbor of node.neighbors) {
      clone.neighbors.push(map[neighbor.val] || dfs(neighbor));
    }
    return clone;
  }
}